package com.ilancuo.thinkinjava.chapter_16;

import java.util.Arrays;

public class CopyingArrays {
    public static void main(String[] args) {
        int[] i = new int[7];
        int[] j = new int[10];
        Arrays.fill(i, 47);
        Arrays.fill(j, 99);
        System.out.println("i = " + Arrays.toString(i));    //i = [47, 47, 47, 47, 47, 47, 47]
        System.out.println("j = " + Arrays.toString(j));    //j = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99]
        System.arraycopy(i, 0, j, 0, i.length);
        System.out.println("j = " + Arrays.toString(j));    //j = [47, 47, 47, 47, 47, 47, 47, 99, 99, 99]
        int[] k = new int[5];
        Arrays.fill(k, 103);
        System.arraycopy(i, 0, k, 0, k.length);
        System.out.println("k = " + Arrays.toString(k));    //k = [47, 47, 47, 47, 47]
        Arrays.fill(k, 103);
        System.arraycopy(k, 0, i, 0, k.length);
        System.out.println("i = " + Arrays.toString(i));    //i = [103, 103, 103, 103, 103, 47, 47]

        Integer[] u = new Integer[10];
        Integer[] v = new Integer[5];
        Arrays.fill(u, 47);
        Arrays.fill(v, 99);
        System.out.println("u = " + Arrays.toString(u));    //u = [47, 47, 47, 47, 47, 47, 47, 47, 47, 47]
        System.out.println("v = " + Arrays.toString(v));    //v = [99, 99, 99, 99, 99]
        System.arraycopy(v, 0, u, u.length / 2, v.length);
        System.out.println("u = " + Arrays.toString(u));    //u = [47, 47, 47, 47, 47, 99, 99, 99, 99, 99]
    }
}
